package com.diqizu.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.diqizu.entity.DisPlay;
import com.diqizu.entity.Images;
import com.diqizu.utli.DBManager;
import com.diqizu.utli.QueryDataResult;

public class ImgDaoImpl {

	public ArrayList<Images> imgall(){
		
		 String sql ="select * from imges";
		   
		    System.out.println("执行的语句是"+sql);
		    QueryDataResult execQuery = DBManager.execQuery(sql);
		     ArrayList<Images> list= new ArrayList<Images>();
		    if(execQuery!=null) {
		      ResultSet rs=execQuery.rs;
		      try {
		        while(rs.next()) {
		        	Images e1=new Images(rs.getInt("imgid"),rs.getString("imgurl"),rs.getInt("productid"),rs.getString("imgname"));
		          
		          list.add(e1);  
		        }
		        }catch(SQLException e1){
		          e1.printStackTrace();
		        }finally {
		          execQuery.close();
		        }
		      }
		      return list; 
	}
	
	 //插入的方法
    public boolean insertproduct(Images Images) {
 	   
 	   String sql="insert into imges (imgid,imgurl,productid,imgname)"
 	   		+ " values('"+Images.getImgid()+"','"+Images.getImgurl()+"','"+Images.getProductid()+"','"+Images.getImgname()+"')";
 	   
 	   System.out.println("执行的语句是"+sql);
 	   return DBManager.execUpdate(sql);
 	   
    }
	
	
  //修改方法
    public boolean updateproductimg(Images Images) {
		String sql ="update imges set imgurl='"+Images.getImgurl()+"',productid='"+Images.getProductid()+"',imgname='"+Images.getImgname()+"' where imgid='"+Images.getImgid()+"'";
		System.out.println("执行的语句是："+sql);
		return DBManager.execUpdate(sql);
	}
    
    //删除
     public boolean deleteproductimg(int imgid) {
 		String sql ="delete from imges where imgid ="+imgid;
 		System.out.println("执行的语句是："+sql);
 		return DBManager.execUpdate(sql);
 		
 	}
	
     public ArrayList<Images> getListByPid(String pid) {
 		String sql = "select * from imges where productid="+pid;
 		System.out.println("执行的sql语句是:" + sql);
 		QueryDataResult execQuery = DBManager.execQuery(sql);
 		ArrayList<Images> list = new ArrayList<Images>();
 		if (execQuery != null) {
 			ResultSet rs = execQuery.rs;
 			try {
 				while (rs.next()) {
 					Images e1=new Images(rs.getInt("imgid"),rs.getString("imgurl"),rs.getInt("productid"),rs.getString("imgname"));
 			          
 			          list.add(e1); 
 				}
 			} catch (SQLException e) {
 				e.printStackTrace();
 			} finally {
 				execQuery.close();
 			}
 		}
 		System.out.println("查到的数据是："+list);
 		return list;
 	}
	
	
	
	
	
	
	
	
	
	
	
}
